const formatTime = date => {
  if(!date){
    date=  new Date(Date.now())
  }
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


//ArrayBuffer转字符串
function arrayBufferToStr(ab) {
  let unit8Arr = new Uint8Array(ab);
  let encodedString = String.fromCharCode.apply(null, unit8Arr),
    decodedString = decodeURIComponent(escape((encodedString)));//没有这一步中文会乱码
  return decodedString
}






module.exports = {
  formatTime: formatTime,
  arrayBufferToStr: arrayBufferToStr,
}
